package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.NodeDecisionDTO;
import cn.com.blueInfo.bpm.template.response.NodeDecisionVO;
import cn.com.blueInfo.bpm.template.service.NodeDecisionService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 节点流转规则表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "节点流转规则 接口")
@RestController
@RequestMapping("/template/nodeDecision")
public class NodeDecisionController extends BaseController {

    @Autowired
    private NodeDecisionService nodeDecisionService;

    /**
     * 新建节点流转规则
     * @param nodeDecisionDTO 节点流转规则参数
     * @return ResultInfo
     */
    @Operation(summary = "新增节点流转规则")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createNodeDecision(
            @Validated({Create.class, Default.class}) @RequestBody NodeDecisionDTO nodeDecisionDTO) {
        return nodeDecisionService.addNodeDecision(nodeDecisionDTO);
    }

    /**
     * 批量新建节点流转规则
     * @param nodeDecisionDTOList 节点流转规则参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建节点流转规则")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateNodeDecision(
            @Validated({Create.class, Default.class}) @RequestBody List<NodeDecisionDTO> nodeDecisionDTOList) {
        return nodeDecisionService.batchAddNodeDecision(nodeDecisionDTOList);
    }

    /**
     * 根据ID删除节点流转规则
     * @param nodeDecisionId 节点流转规则ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除节点流转规则")
    @DeleteMapping("/removeInfo/{nodeDecisionId}")
    public ResultInfo<Integer> deleteNodeDecisionById(
            @Parameter(name = "ID") @PathVariable Long nodeDecisionId) {
        return nodeDecisionService.removeNodeDecision(nodeDecisionId);
    }

    /**
     * 批量根据ID删除节点流转规则
     * @param nodeDecisionIdList 节点流转规则ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除节点流转规则")
    @DeleteMapping("/removeInfoList/{nodeDecisionIdList}")
    public ResultInfo<Integer> batchDeleteNodeDecisionById(
            @Parameter(name = "ID") @PathVariable List<Long> nodeDecisionIdList) {
        return nodeDecisionService.batchRemoveNodeDecision(nodeDecisionIdList);
    }

    /**
     * 根据ID全量更新节点流转规则
     * @param nodeDecisionId 节点流转规则ID
     * @param nodeDecisionDTO 节点流转规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新节点流转规则")
    @PutMapping("/modifyInfo/{nodeDecisionId}")
    public ResultInfo<Integer> updateNodeDecisionFull(
            @Parameter(name = "ID") @PathVariable Long nodeDecisionId,
            @Validated({Update.class, Default.class}) @RequestBody NodeDecisionDTO nodeDecisionDTO) {
        validateUpdateId(nodeDecisionId, nodeDecisionDTO.getId());
        return nodeDecisionService.modifyNodeDecision(nodeDecisionDTO);
    }

    /**
     * 根据ID部分更新节点流转规则
     * @param nodeDecisionId 节点流转规则ID
     * @param nodeDecisionUpdatePartialDTO 节点流转规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新节点流转规则")
    @PatchMapping("/modifyPartialInfo/{nodeDecisionId}")
    public ResultInfo<Integer> updateNodeDecisionPartial(
            @Parameter(name = "ID") @PathVariable Long nodeDecisionId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            NodeDecisionDTO.UpdatePartialDTO nodeDecisionUpdatePartialDTO) {
        validateUpdateId(nodeDecisionId, nodeDecisionUpdatePartialDTO.getId());
        return nodeDecisionService.modifyNodeDecisionPartial(nodeDecisionUpdatePartialDTO);
    }

    /**
     * 根据ID查询节点流转规则
     * @param nodeDecisionId 节点流转规则ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询节点流转规则")
    @GetMapping("/getInfo/{nodeDecisionId}")
    public ResultInfo<NodeDecisionVO> getNodeDecisionById(
            @Parameter(name = "ID") @PathVariable Long nodeDecisionId) {
        return nodeDecisionService.queryNodeDecisionById(nodeDecisionId);
    }

    /**
     * 分页查询节点流转规则
     * @param nodeDecisionQueryDTO 节点流转规则参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询节点流转规则")
    @GetMapping("/getInfos")
    public ResultInfo<Page<NodeDecisionVO>> getNodeDecisionPage(
            @Validated NodeDecisionDTO.QueryDTO nodeDecisionQueryDTO) {
        return nodeDecisionService.queryNodeDecisionPage(nodeDecisionQueryDTO);
    }

    /**
     * 根据条件查询节点流转规则
     * @param nodeDecisionQueryDTO 节点流转规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询节点流转规则")
    @GetMapping("/getInfoList")
    public ResultInfo<List<NodeDecisionVO>> getNodeDecisionList(
            @Validated NodeDecisionDTO.QueryDTO nodeDecisionQueryDTO) {
        return nodeDecisionService.queryNodeDecisionList(nodeDecisionQueryDTO);
    }

}
